﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace FeatureFlags
{
    class Program
    {
        static Dictionary<int, string> featureFlags = new Dictionary<int, string>() 
        {
            { 1, "Livechat" },
            { 2, "Bot" },
            { 4, "Voicebot" },
            { 8, "Knowlegbase" },
            { 16, "Taskbot" },
        };
        static int CalculeFeaturePoint(IEnumerable<string> features)
        {
            var point = 0;
            foreach (var feature in features.Distinct())
            {
                var featureFlag = featureFlags.FirstOrDefault(f => f.Value == feature);
                point += featureFlag.Key;
            }
            return point;
        }
        static bool IsFeatureAvailable(int appFeaturePoint, string feature)
        {
            var featureFlag = featureFlags.FirstOrDefault(f => f.Value == feature);
            return (appFeaturePoint & featureFlag.Key) == featureFlag.Key;
        }
        static void Main(string[] args)
        {
            var appFeaturePoint = CalculeFeaturePoint(new List<string>() { "Knowlegbase", "Taskbot" });
            var isFeatureAvailableKb = IsFeatureAvailable(appFeaturePoint, "Knowlegbase");
            var isFeatureAvailableBot = IsFeatureAvailable(appFeaturePoint, "Bot");
            var isFeatureAvailableTaskbot = IsFeatureAvailable(appFeaturePoint, "Taskbot");

            Console.WriteLine("Hello World!");
        }
    }
}
